#!/usr/bin/env python

from re import search
import pdb

BaseIDRegex = "^(\[[0-9a-z]{12}\])"
Table = {
#	"regex":"response string"
    BaseIDRegex + "help":"help information*_*",
    BaseIDRegex + "reset all":"*_*",
	BaseIDRegex + "set ":"Set xxx OK*_*",
	BaseIDRegex + "cal ":"Cal:SetXX OK*_*",
	BaseIDRegex + "meas ":"MeasVoltXX:1.000 V OK*_*",
	BaseIDRegex + "io set":"OK *_*",
	BaseIDRegex + "eeprom enable: ":"EEPROM_XXLOCK OK*_*",
	BaseIDRegex + "eeprom string read":'ACK("V1.0");',
	BaseIDRegex + "version":"V1.234",
	"default":"err*_*",
}

class MapTable(object):
	def __init__(self):
		pass

	def getResponseString(self,input_str):
		# Input check
		if not isinstance(input_str,str):
			print("Error: 'input_str' must be a string.")
			raise TypeError("invalid type for input string.")

		for key in Table.keys():
			# TODO list
			#  1. Match regex with input_str
			regex_ret = search(key,input_str)
			if regex_ret:
				print("Regex > {0}".format(key))
				print("Regex Ret > {0}".format(regex_ret.group(0)))
				ret_str = regex_ret.group(1)+Table[key]
				return ret_str

		#pdb.set_trace()
		return Table["default"]
